//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;
using OpenLS.Core.Serialization;
using System.ComponentModel;

namespace OpenLS.Drawing
{
    public class LineEndProperties : ViewModelBase, IOfficeXmlSerializableAs
    {
        private LineEndLength? len; //\\unit
        private LineEndType type;

        private LineEndWidth? w;

        public LineEndType Type
        {
            get { return type; }
            set { type = value;notifyPropertyChanged("Type"); }
        }

        public LineEndWidth? Width
        {
            get { return w; }
            set { w = value; notifyPropertyChanged("Width");}
        }

        public LineEndLength? Length
        {
            get { return len; }
            set { len = value; notifyPropertyChanged("Length");}
        }

        #region IOfficeXmlSerializableAs Members

        void IOfficeXmlSerializableAs.ReadXmlAs(string name, ReadContext context)
        {
            using (var c = context.Read(name))
            {
                Type = c.GetOptionalEnum("type", LineEndType.None); //\\default?
                Width = c.GetOptionalEnum<LineEndWidth>("w");
                Length = c.GetOptionalEnum<LineEndLength>("len");
            }
        }

        void IOfficeXmlSerializableAs.WriteXmlAs(string name, WriteContext context)
        {
            using (WriteContext c = context.Write(name))
            {
                c.SetEnum("type", Type);
                c.SetOptionalEnum("w", Width);
                c.SetOptionalEnum("len", Length);
            }
        }

        #endregion

    }
}